<?php
declare (strict_types=1);
/**
 * User: 五哥派
 * Date: 2024/7/17
 * Tel(同WX): 17335592719
 */
namespace app\common\lib\exception;

use think\Exception;

/**
 * 自定义异常类的基类
 */
class BaseException extends Exception
{
   /* // 状态码
    public $code;

    // 错误信息
    public $msg = '';

    // 输出的数据
    public $data = [];
*/
    /**
     * 构造函数，接收一个关联数组
     * @param array $params 关联数组只应包含code、msg、data，且不应该是空值
     */
    /* public function __construct($params = [])
    {
        parent::__construct();
        $this->code = $params['code'] ?? 0;
        $this->msg = $params['msg'] ?? '很抱歉，服务器内部错误';
        $this->data = $params['data'] ?? [];
    }*/

    public $code = 400;
    public $msg = '错误请求';
    public $errorCode = 1000;

    public function __construct($params=[])
    {
        if(!is_array($params)){
            return;
        }
        if(array_key_exists('code',$params)){
            $this->code = $params['code'];
        }
        if(array_key_exists('msg',$params)){
            $this->msg = $params['msg'];
        }
        if(array_key_exists('errorCode',$params)){
            $this->errorCode = $params['errorCode'];
        }
    }
}

